<!--
Title: Tigra Calendar
URL: http://www.softcomplex.com/products/tigra_calendar/
Version: 3.2
Date: 05/18/2006
Feedback: feedback@softcomplex.com (specify product title in the subject)
Note: Permission given to use this script in ANY kind of applications if
   header lines are left unchanged.
Note: Script consists of two files: calendar?.js and calendar.html
About us: Our company provides offshore IT consulting services.
    Contact us at sales@softcomplex.com if you have any programming task you
    want to be handled by professionals. Our typical hourly rate is $20.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=ISO-8859-1" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="BR">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    <meta http-equiv="Cache-Control" content="No-Cache"/>
    <meta http-equiv="Pragma" content="No-Cache"/>
    <meta http-equiv="Expires" content="0"/>
    <%--  Application CSS --%>
    <link rel="stylesheet" type="text/css" href="<c:url value="/css/tema/calendario.css"/>"/>
    <title><fmt:message key="page.title"/></title>
      <script language="JavaScript">
      
      // months as they appear in the calendar's title
      var ARR_MONTHS = [<fmt:message key="calendar.months"/>];
      // week day titles as they appear on the calendar
      var ARR_WEEKDAYS = [<fmt:message key="calendar.weekdays"/>];
      // day week starts from (normally 0-Su or 1-Mo)
      var NUM_WEEKSTART = 1;
      // path to the directory where calendar images are stored. trailing slash req.
      var STR_ICONPATH = '<c:url value="/img/"/>';
      
      var re_url = new RegExp('datetime=(\\-?\\d+)');
      var dt_current = (re_url.exec(String(window.location))
      	? new Date(new Number(RegExp.$1)) : new Date());
      var re_id = new RegExp('id=(\\d+)');
      var num_id = (re_id.exec(String(window.location))
      	? new Number(RegExp.$1) : 0);
      var obj_caller = (window.parent ? window.parent.calendars[num_id] : null);
      
      if (obj_caller && obj_caller.year_scroll) {
      	// get same date in the previous year
      	var dt_prev_year = new Date(dt_current);
      	dt_prev_year.setFullYear(dt_prev_year.getFullYear() - 1);
      	if (dt_prev_year.getDate() != dt_current.getDate())
      		dt_prev_year.setDate(0);
      	
      	// get same date in the next year
      	var dt_next_year = new Date(dt_current);
      	dt_next_year.setFullYear(dt_next_year.getFullYear() + 1);
      	if (dt_next_year.getDate() != dt_current.getDate())
      		dt_next_year.setDate(0);
      }
      
      // get same date in the previous month
      var dt_prev_month = new Date(dt_current);
      dt_prev_month.setMonth(dt_prev_month.getMonth() - 1);
      if (dt_prev_month.getDate() != dt_current.getDate())
      	dt_prev_month.setDate(0);
      
      // get same date in the next month
      var dt_next_month = new Date(dt_current);
      dt_next_month.setMonth(dt_next_month.getMonth() + 1);
      if (dt_next_month.getDate() != dt_current.getDate())
      	dt_next_month.setDate(0);
      
      // get first day to display in the grid for current month
      var dt_firstday = new Date(dt_current);
      dt_firstday.setDate(1);
      dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - NUM_WEEKSTART) % 7);
      
      // function passing selected date to calling window
      function set_datetime(n_datetime, b_close) {
      	if (!obj_caller) return;
      
      	var dt_datetime = obj_caller.prs_time(
      		(document.cal ? document.cal.time.value : ''),
      		new Date(n_datetime)
      	);
      
      	if (!dt_datetime) {
            return;
          }
      	if (b_close) {
            obj_caller.target.value = (document.cal
        		? obj_caller.gen_tsmp(dt_datetime)
        		: obj_caller.gen_date(dt_datetime)
            );
            // close active modal window
            window.parent.Windows.getFocusedWindow().close();
      	} else {
            // update calendar dates range using code below must close window like it's above
            //obj_caller.popup(dt_datetime.valueOf());
            document.location.href = '<c:url value="/calendar.do"/>?datetime=' + dt_datetime.valueOf() + '&id=' + obj_caller.id;
          }
      }
      
      </script>
      </head>
      
        <body class="calendar">
          <div id="container">
            <div id="content">
            
            <table class="calendar" cellpadding="1" cellspacing="0">
            	<tr>
      		
      			<script language="JavaScript">
      			document.write(
      			'<th>'+(obj_caller && obj_caller.year_scroll?'<a href="javascript:set_datetime('+dt_prev_year.valueOf()+')" class="calPrevYear" title="<fmt:message key="calendar.previous.year"/>"><span>|&lt;</span></a><br />':'')+'<a href="javascript:set_datetime('+dt_prev_month.valueOf()+')" class="calPrevMonth" title="<fmt:message key="calendar.previous.month"/>"><span>&gt;</span></a></th>'+
      			'<th colspan="5"><span class="year">'+dt_current.getFullYear()+'</span><br /><span class="month">'+ARR_MONTHS[dt_current.getMonth()]+'</span></th>'+
      			'<th>'+(obj_caller && obj_caller.year_scroll?'<a href="javascript:set_datetime('+dt_next_year.valueOf()+')" class="calNextYear title="<fmt:message key="calendar.next.year"/>"><span>&gt;|</span></a><br />':'')+'<a href="javascript:set_datetime('+dt_next_month.valueOf()+')" class="calNextMonth"  title="<fmt:message key="calendar.next.month"/>"><span>&lt;</span></a></th>'
      			);
      			</script>
      		
          	</tr>
          <tr> <td colspan="7">&nbsp;</td></tr>
          <script language="JavaScript">
      
        // print weekdays titles
        document.write('<tr>');
        for (var n=0; n<7; n++)
        	document.write('<td class="weekday">'+ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7]+'</td>');
        document.write('</tr>');
        
        // print calendar table
        var dt_current_day = new Date(dt_firstday);
        while (dt_current_day.getMonth() == dt_current.getMonth() ||
        	dt_current_day.getMonth() == dt_firstday.getMonth()) {
        	// print row heder
        	document.write('<tr>');
        	for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
        		if (dt_current_day.getDate() == dt_current.getDate() &&
        			dt_current_day.getMonth() == dt_current.getMonth())
        			// print current date
        			if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6){
        				document.write('<td class="weekend today">');
        			}else{
        				document.write('<td class="today">');
        			}
        		else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
        			// weekend days
        			document.write('<td class="weekend">');
        		else
        			// print working days of current month
        			document.write('<td class="day">');
        
        		document.write('<a href="javascript:set_datetime('+dt_current_day.valueOf() +', true);">');
        
        		if (dt_current_day.getMonth() == this.dt_current.getMonth())
        			// print days of current month
        			document.write('<span class="currMonth">');
        		else 
        			// print days of other months
        			document.write('<span class="otherMonth">');
        			
        		document.write(dt_current_day.getDate()+'</span></a></td>');
                dt_current_day.setHours(20);
        		dt_current_day.setDate(dt_current_day.getDate()+1);
        	}
        	// print row footer
        	document.write('</tr>');
        }
        if (obj_caller && obj_caller.time_comp)
        	document.write('<form onsubmit="javascript:set_datetime('+dt_current.valueOf()+', true)" name="cal"><tr><td colspan="7" class="weekday">Time: <input type="text" name="time" value="'+obj_caller.gen_time(this.dt_current)+'" size="8" maxlength="8"></td></tr></form>');
      </script>

		</table>

     </div>
    </div>
  </body>
</html>

